package com.example.demo.Spire.DocForJava;

import com.spire.doc.*;
import com.spire.doc.documents.BookmarksNavigator;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.TextWrappingStyle;
import com.spire.doc.fields.DocPicture;

public class AddImgToBookmarkcontent {
    public static void main(String[]args){
        //加载包含书签的文档
        Document doc = new Document();
        doc.loadFromFile("D:\\xrb.docx");

        //定位到指定书签位置起始标签位置，插入图片
        BookmarksNavigator bookmarksNavigator1 = new BookmarksNavigator(doc);
        bookmarksNavigator1.moveToBookmark("test",true,true);
        Paragraph para = new Paragraph(doc);
        DocPicture picture = para.appendPicture("D:\\head.png");
        picture.setWidth(100f);
        picture.setHeight(100f);
        picture.setTextWrappingStyle(TextWrappingStyle.Through);
        bookmarksNavigator1.insertParagraph(para);

        //定位到指定书签位置末尾标签位置，插入文本
        BookmarksNavigator bookmarksNavigator2 = new BookmarksNavigator(doc);
        bookmarksNavigator2.moveToBookmark("书签1",false,true);
        bookmarksNavigator2.insertText("新插入的文本!!!");

        //保存文档
        doc.saveToFile("添加文本、图片到书签.docx",FileFormat.Docx_2013);
        doc.dispose();
    }
}